package com.insmess.speech.service.impl;

import com.insmess.speech.common.util.HotWordUtils;
import com.insmess.speech.common.util.SensitiveWordUtils;
import com.insmess.speech.sdk.dto.TextResponseDto;
import com.insmess.speech.sdk.template.InsmessTextTemplate;
import com.insmess.speech.service.TextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TextServiceImpl implements TextService {
    @Autowired
    private InsmessTextTemplate insmessTextTemplate;
    @Override
    public String punctuation(String text) {
        TextResponseDto responseDto = insmessTextTemplate.textPuncRequest(text);
        if (responseDto.getCode().equals(200)) {
            return responseDto.getResult().getPuncText();
        }
        throw new RuntimeException("添加标点失败");
    }

    @Override
    public String smoothText(String text) {
        throw new RuntimeException("该方法尚未实现");
    }

    @Override
    public String numberReverse(String text) {
        TextResponseDto responseDto = insmessTextTemplate.textNumberReverseRequest(text);
        if (responseDto.getCode().equals(200)) {
            return responseDto.getResult().getPuncText();
        }
        throw new RuntimeException("文本逆向失败");
    }

    @Override
    public String sensitiveFilter(String text) {
        List<String> sensitiveWordList = SensitiveWordUtils.getSensitiveWordList();
        for (String str : sensitiveWordList) {
            text = text.replaceAll(str, "**");
        }
        return text;
    }

    @Override
    public String hotWord(String text) {
        return HotWordUtils.hotWord(text);
    }
}
